package com.connection.second.wallpaper.controller;

import java.util.List;
import java.util.Map;
import java.util.Optional;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.connection.second.common.annotation.Anonymous;
import com.connection.second.wallpaper.domain.vo.ClassifyNamesVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.connection.second.common.annotation.Log;
import com.connection.second.common.core.controller.BaseController;
import com.connection.second.common.core.domain.AjaxResult;
import com.connection.second.common.enums.BusinessType;
import com.connection.second.wallpaper.domain.entity.PaperClassify;
import com.connection.second.wallpaper.service.IPaperClassifyService;
import com.connection.second.common.utils.poi.ExcelUtil;
import com.connection.second.common.core.page.TableDataInfo;

/**
 * 分类管理Controller
 * 
 * @author FL
 * @date 2024-11-12
 */
@RestController
@RequestMapping("/wallpaper/classify")
public class PaperClassifyController extends BaseController
{
    @Resource
    private IPaperClassifyService paperClassifyService;

    /**
     * 查询分类列表
     */
    @Anonymous
    @GetMapping("/list")
    public TableDataInfo list(PaperClassify paperClassify)
    {
        startPage();
        List<PaperClassify> list = paperClassifyService.selectPaperClassifyList(paperClassify);
        return getDataTable(list);
    }

    /**
     * 获取分类名称列表
     */
    @Anonymous
    @GetMapping("/names/{type}")
    public AjaxResult getNameList(@PathVariable("type") String type)
    {
        List<ClassifyNamesVo> list = paperClassifyService.selectClassifyNameList(Integer.parseInt(type));
        return AjaxResult.success(list);
    }

    /**
     * 导出分类管理列表
     */
    @PreAuthorize("@ss.hasPermi('wallpaper:classify:export')")
    @Log(title = "分类管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PaperClassify paperClassify)
    {
        List<PaperClassify> list = paperClassifyService.selectPaperClassifyList(paperClassify);
        ExcelUtil<PaperClassify> util = new ExcelUtil<PaperClassify>(PaperClassify.class);
        util.exportExcel(response, list, "分类管理数据");
    }

    /**
     * 获取分类管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('wallpaper:classify:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(paperClassifyService.selectPaperClassifyById(id));
    }

    /**
     * 新增分类管理
     */
    @PreAuthorize("@ss.hasPermi('wallpaper:classify:add')")
    @Log(title = "分类管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PaperClassify paperClassify)
    {
        return toAjax(paperClassifyService.insertPaperClassify(paperClassify));
    }

    /**
     * 修改分类管理
     */
    @PreAuthorize("@ss.hasPermi('wallpaper:classify:edit')")
    @Log(title = "分类管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PaperClassify paperClassify)
    {
        return toAjax(paperClassifyService.updatePaperClassify(paperClassify));
    }

    /**
     * 删除分类管理
     */
    @PreAuthorize("@ss.hasPermi('wallpaper:classify:remove')")
    @Log(title = "分类管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(paperClassifyService.deletePaperClassifyByIds(ids));
    }
}
